#ifndef __X_WR_ASIO_H_
#define __X_WR_ASIO_H_
#include "j_includes.h"
#include "j_type.h"
#include "x_singleton.h"
#include "x_lock.h"
#include "x_socket.h"

#define IN_FILES		100
#define MAX_BUFFER_SIZE		1024
#define TIME_DELAY	6000
class CWrAsio : public SingletonTmpl<CWrAsio>
{
public:
	CWrAsio();
	~CWrAsio();

public:
	int Init();
	void Deinit();
	int AddUser(int nSocket, J_AsioUser *pUser);
	void DelUser(int nSocket);

private:
	static void *WorkThread(void *param)
	{
		(static_cast<CWrAsio *>(param))->OnWork();
		return (void *)0;
	}
	void OnWork();

private:
	typedef std::map<int, J_AsioUser *> AsioMap;
	AsioMap m_asioMap;

	pthread_t m_workThread;
	J_OS::CTLock m_locker;

	struct pollfd m_fds[IN_FILES];
	bool m_bStarted;
};

#endif //~__X_WR_ASIO_H_
